package com.example.teamtribe.main.mine.club;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.widget.TextView;

import com.example.teamtribe.R;
import com.example.teamtribe.base.BaseActivity;
import com.example.teamtribe.database.Team;
import com.example.teamtribe.utils.Utility;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ClubActivity extends BaseActivity implements XRecyclerView.LoadingListener {

    private XRecyclerView xRecyclerView;
    private ClubGridAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_club);
        ((TextView) findViewById(R.id.tv_title)).setText("我的社团");
        xRecyclerView = findViewById(R.id.rv_club_list);
        xRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
        xRecyclerView.setRefreshHeader(xRecyclerView.getDefaultRefreshHeaderView());
        xRecyclerView.setLoadingListener(this);
        adapter = new ClubGridAdapter();

        Random random = new Random(10);
        List<Integer> temps = new ArrayList<>();
        List<Team> teams = new ArrayList<>();
        while (teams.size() < 6) {
            int id = random.nextInt(20) + 1;
            if (!temps.contains(id)) {
                temps.add(id);
                teams.add(Utility.getT(id, Team.class));
            }
        }
        adapter.addAll(teams);

        xRecyclerView.setAdapter(adapter);
    }

    @Override
    public void onRefresh() {
        xRecyclerView.refreshComplete();
    }

    @Override
    public void onLoadMore() {
        xRecyclerView.loadMoreComplete();
    }
}
